package org.hiucung.desktoptranslationtools.dialog

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import org.hiucung.desktoptranslationtools.bean.DialogEvent


/**
 * @title: MaterialDialog
 * @projectName DesktopTranslationTools
 * @description: 材料库通用弹窗
 * @author Kicc
 * @date 2025/7/24 3:42
 */
@Composable
fun MaterialDialog(
    event: DialogEvent,
    onDismiss: () -> Unit
) {
    AlertDialog(
        onDismissRequest = onDismiss,
        properties = DialogProperties(dismissOnClickOutside = false),
        shape = MaterialTheme.shapes.extraLarge,
        tonalElevation = 6.dp,
        title = {
            Text(
                text = when (event) {
                    is DialogEvent.Info -> event.title
                    is DialogEvent.Error -> event.title
                },
                style = MaterialTheme.typography.headlineSmall
            )
        },
        text = {
            Text(
                text = when (event) {
                    is DialogEvent.Info -> event.message
                    is DialogEvent.Error -> event.message
                },
                style = MaterialTheme.typography.bodyMedium
            )
        },
        confirmButton = {
            FilledTonalButton(
                onClick = onDismiss,
                shape = MaterialTheme.shapes.large,
                colors = ButtonDefaults.filledTonalButtonColors(
                    containerColor = MaterialTheme.colorScheme.primaryContainer,
                    contentColor = MaterialTheme.colorScheme.onPrimaryContainer
                )
            ) {
                Text(
                    text = when (event) {
                        is DialogEvent.Info -> event.confirmText
                        is DialogEvent.Error -> event.confirmText
                    },
                    style = MaterialTheme.typography.labelLarge
                )
            }
        }
    )
}